Skip to content

Conversation

@lukaszkorecki
Copy link

This small change makes system-map work with both key/value pairs and passing the system as a map. A lot of the framework-ish code that I wrote over the years tends to compose systems out of maps, so I never found the use for system-map as is, and instead always used map->SystemMap. With this change we can do both and keep the public facing API somewhat cleaner.

Only downside is that this makes Component require Clojure 1.11 and up as that's when support for kw-args as map was added.

This requires bumping min Clojure version to 1.11
Copilot AI review requested due to automatic review settings November 1, 2025 16:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the system-map function to accept either keyword arguments or a map as input, and updates the Clojure dependency version from 1.7.0 to 1.11.0.

  • Changed the system-map function signature from accepting variadic key-value pairs to using destructured keyword arguments
  • Updated Clojure dependency from version 1.7.0 to 1.11.0
  • Added a test case for passing a map directly to system-map

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/com/stuartsierra/component.cljc Modified system-map function to accept keyword arguments or a map, updated docstring, removed validation logic
test/com/stuartsierra/component_test.clj Added test case for new map-based system-map API
project.clj Updated Clojure dependency from 1.7.0 to 1.11.0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lukaszkorecki
Copy link
Author

Sorry for the AI noise - looks like something was enabled on my end.

@hlship
Copy link

hlship commented Nov 4, 2025

TBH, I think something more useful would be a new function that took var args and broken them into triples: name, component, dependencies.

@lukaszkorecki
Copy link
Author

TBH, I think something more useful would be a new function that took var args and broken them into triples: name, component, dependencies.

Can you expand a bit? Like a combination of system-map and system-using?

@hlship
Copy link

hlship commented Nov 4, 2025

Yes, something like

(component/construct-system
    :foo (map->Foo {}) [:bar]
  :bar (map->Bar {}) nil)

@lukaszkorecki
Copy link
Author

Interesting - I had a similar need of declaratively creating systems, but I went a bit further. I created a library which allows for pure-data definition of component systems:

https://github.com/lukaszkorecki/oreo?tab=readme-ov-file#annotated-example

it doesn't look that different but not sure if it provides what you're after.

@lambdasierra
Copy link
Contributor

Interesting. I mess around with SystemMaps often enough, but usually I'm working with things that are already SystemMaps. If I had a map of components, but not a SystemMap, I would probably do something like (merge (system-map) another-map).

The original system-map takes key-value arguments to mirror array-map and hash-map.

@lukaszkorecki
Copy link
Author

I mess around with SystemMaps often enough, but usually I'm working with things that are already SystemMaps.

For as long as I've been working with Component (over a decade now?) I don't think I ever used system-map beyond simplest of cases (or system-using for that matter), usually application systems are built of out maps and only once the final system shape is constructed it gets passed to map->SystemMap. I guess it just shows how well designed everything is (both Component and Clojure) because technically the function for creating a system out of a map already exists, it's just not part of the "official" API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants